package gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.AbstractDocument;

/**
 * @author Matthias
 *
 */
public class UserMenuAdd extends JPanel{
	
	private JLabel lbl_Header;
	private JTextField textField_AccNr;
	private JLabel lbl_Intro;
	private JLabel lbl_Choice;
	private JRadioButton rdbtn_Credit;
	private JRadioButton rdbtn_Savings;
	private JRadioButton rdbtn_Depot;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JButton btn_Back;
	private JButton btn_Submit;
	
	public UserMenuAdd() {
		
		setPreferredSize(new Dimension(550, 400));
		setLayout(null);
		
		lbl_Header = new JLabel("Add an account");
		lbl_Header.setFont(new Font("SansSerif", Font.BOLD, 26));
		lbl_Header.setBounds(190, 23, 194, 34);
		add(lbl_Header);
		
		textField_AccNr = new JTextField();
		textField_AccNr.addMouseListener(mouseListener);
		textField_AccNr.setToolTipText("8 digits required");
		((AbstractDocument)textField_AccNr.getDocument()).setDocumentFilter(new LimitOfChar(8));
		textField_AccNr.setFont(new Font("SansSerif", Font.PLAIN, 16));
		textField_AccNr.setBounds(70, 122, 160, 30);
		add(textField_AccNr);
		textField_AccNr.setColumns(10);
		
		lbl_Intro = new JLabel("Please type in your preferred accountnumber");
		lbl_Intro.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_Intro.setBounds(70, 90, 344, 21);
		add(lbl_Intro);
		
		lbl_Choice = new JLabel("Please select an account type");
		lbl_Choice.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_Choice.setBounds(70, 172, 242, 21);
		add(lbl_Choice);
		
		rdbtn_Credit = new JRadioButton("Credit");
		rdbtn_Credit.addMouseListener(mouseListener);
		rdbtn_Credit.setToolTipText("Only one Credit account allowed");
		rdbtn_Credit.setFont(new Font("SansSerif", Font.BOLD, 16));
		buttonGroup.add(rdbtn_Credit);
		rdbtn_Credit.setBounds(112, 200, 80, 23);
		add(rdbtn_Credit);
		
		rdbtn_Savings = new JRadioButton("Savings");
		rdbtn_Savings.addMouseListener(mouseListener);
		rdbtn_Savings.setToolTipText("Only one Savings account allowed");
		rdbtn_Savings.setFont(new Font("SansSerif", Font.BOLD, 16));
		buttonGroup.add(rdbtn_Savings);
		rdbtn_Savings.setBounds(203, 200, 87, 23);
		add(rdbtn_Savings);
		
		rdbtn_Depot = new JRadioButton("Depot");
		rdbtn_Depot.addMouseListener(mouseListener);
		rdbtn_Depot.setToolTipText("Only one Depot account allowed");
		rdbtn_Depot.setFont(new Font("SansSerif", Font.BOLD, 16));
		buttonGroup.add(rdbtn_Depot);
		rdbtn_Depot.setBounds(304, 200, 80, 23);
		add(rdbtn_Depot);
		
		btn_Submit = new JButton("Submit");
		btn_Submit.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Submit.setBounds(380, 300, 100, 40);
		add(btn_Submit);
		
		btn_Back = new JButton("Back");
		btn_Back.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Back.setBounds(70, 300, 100, 40);
		add(btn_Back);
	}
	
	public void addActionListener(ActionListener e){
		btn_Back.addActionListener(e);
		btn_Submit.addActionListener(e);
	}
	
	public void clearField(){
		textField_AccNr.setText("");
		buttonGroup.clearSelection();
	}

	public int getAccNr(){
		int AccNr = 0;
		try{
			AccNr = Integer.parseInt(textField_AccNr.getText().trim());
		} catch (Exception exc) {
		}
		return AccNr;
	}
	
	public JButton getBack(){
		return btn_Back;
	}
	
	public JButton getSubmit(){
		return btn_Submit;
	}

	public JRadioButton getRdbtnCredit() {
		return rdbtn_Credit;
	}

	public JRadioButton getRdbtnSavings() {
		return rdbtn_Savings;
	}

	public JRadioButton getRdbtnDepot() {
		return rdbtn_Depot;
	}
	
	MouseListener mouseListener = new MouseAdapter(){    
	    final int defaultTimeout = ToolTipManager.sharedInstance().getInitialDelay();

	    @Override
	    public void mouseEntered(MouseEvent e) {
	        ToolTipManager.sharedInstance().setInitialDelay(0);
	    }

	    @Override
	    public void mouseExited(MouseEvent e) {
	        ToolTipManager.sharedInstance().setInitialDelay(defaultTimeout);
	    }
	};
	
}
